package com.yakuj3.android.comptadroid.DAO;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;

import com.yakuj3.android.comptadroid.data.Operation;

public class OperationDAO extends DAOBase {

	public static final String TABLE_NAME = "operation";
	public static final String KEY = "id";
	public static final String MONTH = "mois";
	public static final String LIBELE = "libele";
	public static final String MONTANT = "montant";
	 
	public OperationDAO(Context pContext) {
		super(pContext);
	}

	public void insert(Operation o)
	{
		ContentValues cv = new ContentValues();
		
		cv.put(MONTH, o.getMonth());
		cv.put(LIBELE, o.getLibele());
		cv.put(MONTANT, o.getMontantAsInteger());
		
		mDb.insert(TABLE_NAME, null, cv);
	}
	
	public Cursor getAllDataForMonth(String month)
	{
		String sqlQ = "SELECT rowid _id,* FROM " + TABLE_NAME + " WHERE " + MONTH + " = ?";
		
		return mDb.rawQuery(sqlQ, new String[] {month});
	}
	
	public void delete(long id)
	{
		mDb.delete(TABLE_NAME, KEY + " = ?", new String[] {String.valueOf(id)});
	}
	
	public void update(Operation o)
	{
		ContentValues cv = new ContentValues();
		
		cv.put(MONTH, o.getMonth());
		cv.put(LIBELE, o.getLibele());
		cv.put(MONTANT, o.getMontantAsInteger());
		
		mDb.update(TABLE_NAME, cv, KEY  + " = ?", new String[] {String.valueOf(o.getId())});
	}
	
	public void select(long id)
	{
		
	}
	
	public ArrayList<Operation> selectWithMonth(String month)
	{
		return null;
	}
	
	public void changeYear(String[] months)
	{
		for (int i = 0; i < months.length; i++)
		{
			mDb.delete(TABLE_NAME, MONTANT + " = ?", new String[] {months[i]});
		}
	}
}
